package com.cluster.platform.controller;

import com.cluster.platform.common.api.CommonResult;
import com.cluster.platform.dto.CmsChannelInfoDto;
import com.cluster.platform.model.CmsChannelInfo;
import com.cluster.platform.service.CmsChannelInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: CmsChannelInfoController
 */
@RestController
@Api(tags = "栏目管理接口", value = "CmsChannelInfoController")
@RequestMapping("/cmsChannel")
public class CmsChannelInfoController {

    @Autowired
    private CmsChannelInfoService cmsChannelInfoService;

    // 分页查询
    @ApiOperation("栏目分页查询")
    @RequestMapping(value = "/searchChannel", method = RequestMethod.POST)
    public CommonResult<Object> searchChannel(@RequestBody CmsChannelInfoDto cmsChannelInfoDto) {
        return cmsChannelInfoService.searchChannelPage(cmsChannelInfoDto);
    }

    // 新增
    @ApiOperation("新增")
    @RequestMapping(value = "/addChannel", method = RequestMethod.POST)
    public CommonResult<Object> addChannel(@RequestBody CmsChannelInfo cmsChannelInfo) {
        return cmsChannelInfoService.addChannel(cmsChannelInfo);
    }

    // 修改
    @ApiOperation("修改栏目")
    @RequestMapping(value = "/updateChannel", method = RequestMethod.PUT)
    public CommonResult<Object> updateChannel(@RequestBody CmsChannelInfo cmsChannelInfo) {
        return cmsChannelInfoService.updateChannel(cmsChannelInfo);
    }

    // 删除
    @ApiOperation("删除栏目")
    @RequestMapping(value = "/delChannel", method = RequestMethod.DELETE)
    public CommonResult<Object> delChannel(@RequestBody CmsChannelInfo cmsChannelInfo) {
        return cmsChannelInfoService.delChannel(cmsChannelInfo);
    }

    // 批量操作
    @ApiOperation("批量操作")
    @RequestMapping(value = "/batchChannel", method = RequestMethod.PUT)
    public CommonResult<Object> batchChannel(@RequestParam("status") Integer status, @RequestParam("ids") List<String> ids) {
        return cmsChannelInfoService.batchChannel(status, ids);
    }

    // 树状栏目菜单
    @ApiOperation("栏目树状菜单")
    @GetMapping("/getChannelTree")
    public CommonResult<Object> getChannelTree() {
        return cmsChannelInfoService.getChannelTree();
    }

    // 查询所有栏目
    @ApiOperation("查询所有栏目")
    @GetMapping("/getChannelList")
    public CommonResult<Object> getChannelList() {
        return cmsChannelInfoService.getChannelList();
    }

}
